package chapter5.No5_1_定时器Timer的使用.demo7;

import java.util.Calendar;
import java.util.Date;
import java.util.Timer;

/**
 * Timer的cancel()方法是清楚所有的任务
 * 并且停止线程
 */
public class Main {
    public static void main(String[] args) throws InterruptedException {
        Calendar c = Calendar.getInstance();
        c.add(Calendar.SECOND, 5);
        Date d = c.getTime();
        System.out.println("b预计时间："+d);

        MyTaskA a = new MyTaskA();
        MyTaskB b = new MyTaskB();

        Timer timer = new Timer();
        timer.schedule(a, d, 2000);
        timer.schedule(b, d, 2000);

        Thread.sleep(10000);
        System.out.println("清除："+new Date());
        timer.cancel();
    }
}
